from typing import List

class Solution:
    def maxValueAfterReverse(self, nums: List[int]) -> int:
        """O(n^2)
        """
        sum_ = 0
        s = 0
        u = []
        for i in range(len(nums)-1):
            sum_ += abs(nums[i+1]-nums[i])
            for j in range(i+1, len(nums)):
                stmp = 0
                if i > 0:
                    stmp += abs(nums[j]-nums[i-1])
                    stmp -= abs(nums[i]-nums[i-1])
                if j < len(nums)-1:
                    stmp += abs(nums[i]-nums[j+1])
                    stmp -= abs(nums[j]-nums[j+1])
                if stmp > s:
                    u = [i,j]
                    s = stmp
        print(sum_+s, u)
        return sum_+s

if __name__ == '__main__':
    s = Solution()
    s.maxValueAfterReverse([2,3,1,5,4])
    s.maxValueAfterReverse([2,4,9,24,2,1,10])